package com.qf.smsplatform.strategy.mq;



import com.itqf.smsplatform.common.constant.RabbitMQConstants;
import com.itqf.smsplatform.common.model.StandardSubmit;

import com.qf.smsplatform.strategy.executor.StrategyExecutor;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * TODO：监听pre_send_sms_topic队列中的消息（InterfaceServiceImpl 发送的消息）
 *
 * @projectName: sms_platform
 * @author: 元
 * @date: 2021/8/19 15:27
 */
@Component
public class PreSendListener {

    @Autowired
    private StrategyExecutor executor;


    @RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {

        // 处理消息
        executor.execute(submit);

        //手动ACK
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

    }
}
